<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">复核入库</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="批次号" prop="batchNumber">
          <el-input
            v-model="queryParams.batchNumber"
            placeholder="请输入批次号检索"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status" >
          <el-select
            v-model="queryParams.status"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" class="list-search btn-success" color="#5ED4D4"
            @click="handleQuery"
          >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="list-search"
            @click="resetQuery"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col>
          <el-button
            class="btn-scanCodeDel"
            type="primary"
            icon="el-icon-download"
            size="mini"
            v-hasPermi="['system:productStock:toBeConfirmedListExportExcel']"
            @click="btnExport()"
          >导出</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="productStockList" @row-click="handleView" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="计划编码" align="center" prop="planCode" :show-overflow-tooltip="true" width="180px" />
        <el-table-column label="产品名称" align="center" prop="productBasicName" :show-overflow-tooltip="true" width="180px" />
        <el-table-column label="规格" width="180px"  align="center" prop="specification" :show-overflow-tooltip="true"/>
        <el-table-column label="产品批号" align="center" width="150px" prop="batchNumber" :show-overflow-tooltip="true" />
        <el-table-column label="箱规" align="center" prop="productSpace" :show-overflow-tooltip="true" />
        <el-table-column label="生产序列号" align="center" width="120px" prop="productionSerialNumber" :show-overflow-tooltip="true" />
        <el-table-column label="计划数量" align="center" prop="planNum" :show-overflow-tooltip="true" />
        <el-table-column label="完成数量" align="center" prop="endNum" :show-overflow-tooltip="true" />
        <el-table-column label="待入库" align="center" prop="endNum" :show-overflow-tooltip="true" />
        <el-table-column label="实际入库" align="center" prop="storeNum" :show-overflow-tooltip="true" />
        <el-table-column label="开始时间" align="center" prop="createTime" width="180px" />
        <el-table-column label="结束时间" align="center" prop="updateTime" width="180px" />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 1" style="color:#52C41A">已入库</div>
            <div v-if="scope.row.status == 2" style="color:#13C2C2">待入库</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listProductStock } from "@/api/system/productStockConfirm/productStockConfirm"
import { exportToBeConfirmedListExportExcel } from "@/api/system/export/export"

export default {
  name: "productStock",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 完工入库数据
      productStockList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNumber: undefined,
        status: undefined
      },
      //审核状态
      status:[
        {
          value:'1',
          label:'已入库'
        },
         {
          value:'2',
          label:'待入库'
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      listProductStock(this.addDateRange(this.queryParams)).then((res) => {
        this.productStockList = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 查看详情
    handleView(row) {
      this.$router.push({path:"/production/productstock/confirmdetail",query:{id: row.id}})
    },
    // 导出
    btnExport(){
      let data = {
        batchNumber: this.queryParams.batchNumber,
        status: this.queryParams.status
      }
      this.getExport(data)
    },
    getExport(data){
      this.$modal.loading("正在导出")
      exportToBeConfirmedListExportExcel(data).then(res => {
        this.$modal.closeLoading()
        let blob = new Blob([res], {
          type: res.type,
        })
        let downloadElement = document.createElement("a")
        let href = window.URL.createObjectURL(blob)
        downloadElement.href = href
        downloadElement.download = "复核入库.xls";
        document.body.appendChild(downloadElement)
        downloadElement.click()
        window.URL.revokeObjectURL(href)
      })
    }
  }
}
</script>
